package 复习.面试TOP101.动态规划;

public class 最小花费爬楼梯 {
    public int minCostClimbingStairs (int[] cost) {
        // write code here
        int[] arr = new int[cost.length + 1];
        for (int i = 2; i <= cost.length; i++) {
            arr[i] = Math.min(arr[i - 1] + cost[i - 1],arr[i - 2] + cost[i - 2]);
        }
        return arr[cost.length];
    }
}

/*
public int minCostClimbingStairs (int[] cost) {
        // write code here
        int[] arr = new int[cost.length];
        arr[cost.length - 1] = cost[cost.length - 1];
        arr[cost.length - 2] = cost[cost.length - 2];
        for (int i = arr.length - 3; i >= 0; i--) {
            arr[i] = cost[i] + Math.min(arr[i + 1],arr[i +2]);
        }
        return Math.min(arr[0],arr[1]);
    }
 */